/**
 * 
 */
package com.pxingg.exception;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

/**
 * @author pxingg
 * 
 */
public class XExceptionTest
{
    /**
     * The log of this class
     */
    static Log log = LogFactory.getLog(XExceptionTest.class);

    /**
     * @throws java.lang.Exception
     */
    @BeforeClass
    public static void setUpBeforeClass() throws Exception
    {
    }

    /**
     * @throws java.lang.Exception
     */
    @AfterClass
    public static void tearDownAfterClass() throws Exception
    {
    }

    /**
     * @throws java.lang.Exception
     */
    @Before
    public void setUp() throws Exception
    {
    }

    /**
     * @throws java.lang.Exception
     */
    @After
    public void tearDown() throws Exception
    {
    }

    /**
     * Test method for {@link com.pxingg.exception.XException#getStack(java.lang.Throwable)}.
     */
    @Test
    public final void testGetStack()
    {
        try
        {
            throw new XException(new Throwable());
        }
        catch (final XException e)
        {
            final String expect = "com.pxingg.exception.XException: java.lang.Throwable" + System.getProperty("line.separator") + "\tat com.pxingg.exception.XExceptionTest.testGetStack(XExceptionTest.java:";
            final String actual = XException.getStack(e).substring(0, expect.length());

            System.out.println(expect.length());
            System.out.println(actual.length());

            Assert.assertEquals(expect, actual);
        }
    }

    /**
     * Test method for {@link com.pxingg.exception.XException#XException()}.
     */
    @Test
    public final void testXException()
    {
        try
        {
            throw new XException();
        }
        catch (final XException e)
        {
            Assert.assertNull(e.getMessage());
        }
    }

    /**
     * Test method for {@link com.pxingg.exception.XException#XException(java.lang.String)}.
     */
    @Test
    public final void testXExceptionString()
    {
        try
        {
            throw new XException("my exception");
        }
        catch (final XException e)
        {
            Assert.assertNotNull(e.getMessage());
            Assert.assertEquals(e.getMessage(), "my exception");
        }
    }

    /**
     * Test method for {@link com.pxingg.exception.XException#XException(java.lang.String, java.lang.Throwable)} .
     */
    @Test
    public final void testXExceptionStringThrowable()
    {
        try
        {
            throw new XException("my exception", new Throwable());
        }
        catch (final XException e)
        {
            Assert.assertNotNull(e.getMessage());
            Assert.assertEquals(e.getMessage(), "my exception");
        }
    }

    /**
     * Test method for {@link com.pxingg.exception.XException#XException(java.lang.Throwable)}.
     */
    @Test
    public final void testXExceptionThrowable()
    {
        try
        {
            throw new XException(new Throwable());
        }
        catch (final XException e)
        {
            Assert.assertEquals(e.getMessage(), "java.lang.Throwable");
        }
    }
}
